package com.hivekion.common.exception;

import com.hivekion.common.enums.ResultCodeEnum;

// 自定义异常
public class BusinessException extends RuntimeException {
      private Integer code; // 错误码
      private String message; // 错误信息

      public BusinessException() {
      }

      public BusinessException(Integer code, String message) {
	    super(message);
	    this.code = code;
	    this.message = message;
      }

      public BusinessException(ResultCodeEnum codeEnum) {
	    super(codeEnum.getMessage());
	    this.code = codeEnum.getCode();
	    this.message = codeEnum.getMessage();
      }

      @Override
      public boolean equals(Object o) {
	    if (this == o) return true;
	    if (o == null || getClass() != o.getClass()) return false;
	    BusinessException that = (BusinessException) o;
	    if (!code.equals(that.code)) return false;
	    return message.equals(that.message);
      }

      @Override
      public int hashCode() {
	    int result = code != null ? code.hashCode() : 0;
	    result = 31 * result + (message != null ? message.hashCode() : 0);
	    return result;
      }

      public Integer getCode() {
	    return code;
      }

      @Override
      public String getMessage() {
	    return message;
      }
}
